package com.bigpig245.mangareader;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.bigpig245.mangareader.adapter.SimpleArrayAdapter;
import com.bigpig245.mangareader.entity.AbsImageLink;
import com.bigpig245.mangareader.entity.MFManga;

public class MainActivity extends ListActivity {

	// @SuppressLint("NewApi")
	// @Override
	// protected void onCreate(Bundle savedInstanceState) {
	// // param
	// final Context context = this;
	//
	// final ListView listview = (ListView) findViewById(R.id.mangalist);
	//
	// super.onCreate(savedInstanceState);
	// // connect internet
	// StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
	// .permitAll().build();
	// StrictMode.setThreadPolicy(policy);
	// setContentView(R.layout.activity_main);
	//
	// // check network connectivity
	// ConnectivityManager connMgr = (ConnectivityManager)
	// getSystemService(Context.CONNECTIVITY_SERVICE);
	// NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
	// if (networkInfo != null && networkInfo.isConnected()) {
	// // ImageView imgView = (ImageView) findViewById(R.id.imageView1);
	// // Drawable d = ImageUtils
	// // .getImageFromURL(
	// //
	// "http://examples.javacodegeeks.com/wp-content/uploads/2013/01/package-explorer-main-layout.jpg",
	// // "test");
	// //
	// // imgView.setImageDrawable(d);
	// } else {
	// AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
	// builder1.setMessage("No network");
	// builder1.setCancelable(false);
	// builder1.setPositiveButton("Yes",
	// new DialogInterface.OnClickListener() {
	// public void onClick(DialogInterface dialog, int id) {
	// dialog.cancel();
	// }
	// });
	// builder1.setNegativeButton("No",
	// new DialogInterface.OnClickListener() {
	// public void onClick(DialogInterface dialog, int id) {
	// dialog.cancel();
	// }
	// });
	//
	// AlertDialog alert11 = builder1.create();
	// alert11.show();
	// }
	//
	// // display list manga
	// // Instantiate the list of samples.
	// mangaList = new ArrayList<MFManga>();
	//
	// mangaList.add(new MFManga("DragonBall", ChapterActivity.class));
	// // new MFManga("Detective Conan", ChapterActivity.class),
	// // new MFManga("Beelzebub", ChapterActivity.class),
	// // new MFManga("One Piece", ChapterActivity.class),
	// // new MFManga("One Piece", ChapterActivity.class),
	// // new MFManga("One Piece", ChapterActivity.class),
	// // new MFManga("One Piece", ChapterActivity.class),
	// // new MFManga("One Piece", ChapterActivity.class),
	// // new MFManga("One Piece", ChapterActivity.class),
	// // new MFManga("Naruto", ChapterActivity.class), };
	//
	// mangaNames = new ArrayList<String>();
	// mangaNames.add("mangaNames");
	//
	// final StableArrayAdapter adapter = new StableArrayAdapter(this,
	// android.R.layout.simple_list_item_1, mangaNames);
	// listview.setAdapter(adapter);
	//
	// listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
	//
	// @Override
	// public void onItemClick(AdapterView<?> parent, final View view,
	// int position, long id) {
	// final String item = (String) parent.getItemAtPosition(position);
	// view.animate().setDuration(2000).alpha(0)
	// .withEndAction(new Runnable() {
	// @Override
	// public void run() {
	// mangaNames.add(item);
	// adapter.notifyDataSetChanged();
	// view.setAlpha(1);
	// }
	// });
	// }
	//
	// });
	// // end display list manga
	// }
	//
	// @Override
	// public boolean onCreateOptionsMenu(Menu menu) {
	// // Inflate the menu; this adds items to the action bar if it is present.
	// getMenuInflater().inflate(R.menu.main, menu);
	// return true;
	// }
	//
	// @Override
	// protected void onListItemClick(ListView listView, View view, int
	// position,
	// long id) {
	// // Launch the sample associated with this list position.
	// startActivity(new Intent(MainActivity.this, mangaList.get(position)
	// .getActivityClass()));
	// }
	//
	// private class StableArrayAdapter extends ArrayAdapter<String> {
	//
	// HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
	//
	// public StableArrayAdapter(Context context, int textViewResourceId,
	// List<String> objects) {
	// super(context, textViewResourceId, objects);
	// for (int i = 0; i < objects.size(); ++i) {
	// mIdMap.put(objects.get(i), i);
	// }
	// }
	//
	// @Override
	// public long getItemId(int position) {
	// String item = getItem(position);
	// return mIdMap.get(item);
	// }
	//
	// @Override
	// public boolean hasStableIds() {
	// return true;
	// }
	//
	// }

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		List<AbsImageLink> mangaList = new ArrayList<AbsImageLink>();
		mangaList.add(new MFManga("Beelzebub", ChapterActivity.class));
		mangaList.add(new MFManga("Conan", ChapterActivity.class));
		mangaList.add(new MFManga("Dragon Ball", ChapterActivity.class));
		mangaList.add(new MFManga("Manga Fox", ChapterActivity.class));
		mangaList.add(new MFManga("Manga Reader", ChapterActivity.class));

		SimpleArrayAdapter adapter = new SimpleArrayAdapter(this, mangaList);

		setListAdapter(adapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		MFManga item = (MFManga) getListAdapter().getItem(position);
		startActivity(new Intent(MainActivity.this, item.getActivityClass()));
		// Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
	}

}
